var windowName = "userMoneyXuni";
var Page,logFenhone,logZengzhi
apiready = function(){
    console.log("index page is OK");
    logFenhone = new List();
    logZengzhi = new List();
    Page = createVM("#Page",{
        //页面数据
        money:{"yue":0,"bao":0,"jifen":0,"xuni":0,"exp":0,"guquan":0}
        ,total:"数据获取中……"
        ,curTab:0
        ,toXuni:""
        ,toLock:""
        ,backXuni:""
        ,backLock:""
        ,page:""
        ,logFenhone:[]
        ,logZengzhi:[]

    },{
        //页面方法
        "init":function () {
            showLoading();
            getData(this)
            // getIntro()
            var page = getLocData("INSURE_INTRO");
            if (isTrue(page)) {
                Page.page = page
            }
            //
            // logFenhone.setUrl("/app/user/money/log").setData({type:"fenhong"}).setCbFunc(function (res) {
            //     clearLoading();
            //     logJson(res,"logYue")
            //     Page.logFenhone = res
            // }).getList();
            logZengzhi.setUrl("/app/user/money/log").setData({type:"zengzhi"}).setCbFunc(function (res) {
                clearLoading();
                logJson(res,"logYue")
                Page.logZengzhi = res
            }).getList();
        }
        , moveToXuni: function () {
            if (!isTrue(this.toXuni)) {
                showToast("请输入转账金额");
                return false;
            }
            apiPost("/app/user/money/move", {money: this.toXuni}, function (res) {
                logJson(res,"/app/user/money/move__")
                showToast(res.message)
                showLoading();
                Page.toXuni = ""
                getData(Page)
            });
        }
        , moveToLock: function () {
            if (!isTrue(this.toLock)) {
                showToast("请输入转账金额");
                return false;
            }
            apiPost("/app/user/money/freeze", {money: this.toLock}, function (res) {
                logJson(res,"/app/user/money/freeze__")
                showToast(res.message)
                showLoading();
                getData(Page)
                Page.toLock = ""
            });
        }
        , moveBackXuni: function () {
            if (!isTrue(this.backXuni)) {
                showToast("请输入转账金额");
                return false;
            }
            apiPost("/app/user/money/back", {money: this.backXuni}, function (res) {
                logJson(res,"/app/user/money/back__")
                showToast(res.message)
                showLoading();
                Page.backXuni = ""
                getData(Page)
            });
        }
        , moveBackLock: function () {
            if (!isTrue(this.backLock)) {
                showToast("请输入转账金额");
                return false;
            }
            apiPost("/app/user/money/unfreeze", {money: this.backLock}, function (res) {
                logJson(res,"/app/user/money/unfreeze__")
                showToast(res.message)
                showLoading();
                getData(Page)
                Page.backLock = ""
            });
        }
    })

    Page.init()

    onWindowShow(function () {
        getData(Page)
    })
    onWindowHide(function () {

    })
    onPullUpLoadMore(function () {
        logZengzhi.getList();
    })
}

function getData(_this) {
    apiGet("/app/user/money",{},function (res,code) {
        clearLoading();
        logJson(res);
        _this.money = res.data;
        _this.total = (res.data.yue + res.data.bao + res.data.xuni + res.data.guquan).toFixed(2)
    })
}

function getIntro() {

    apiGet("/app/page",{code:"INCOME_INTRO"},function (res,code) {
        logJson(res,"page ——res")
        setLocData("INCOME_INTRO",res.data)
        Page.page = res.data
    })
}